package cn.accp.war;

import java.util.Random;
import java.util.Scanner;

import cn.accp.war.baseEntity.Hero;
import cn.accp.war.baseEntity.Monster;
import cn.accp.war.baseEntity.impl.Barbarian;
import cn.accp.war.baseEntity.impl.LandMonster;
import cn.accp.war.baseEntity.impl.Magician;
import cn.accp.war.baseEntity.impl.Ranger;
import cn.accp.war.baseEntity.impl.SeaMonster;
import cn.accp.war.baseEntity.impl.SkyMonster;

public class Game {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int choice;
		do {
			System.out.println("请选择出场英雄：");
			System.out.println("1.魔法师");
			System.out.println("2.野蛮人");
			System.out.println("3.弓箭手");
			System.out.println("4.游戏退出");
			choice = input.nextInt();
		} while (choice < 1 || choice > 4);
		if (choice == 4) {
			System.out.println("游戏退出了，再见！");
		} else {
			Random random = new Random();
			Game game = new Game();
			Monster monster = game.creatMonster(random.nextInt(3) + 1);
			Hero hero = game.creatHero(choice);
			game.battle(hero, monster);
		}
	}

	public void battle(Hero hero, Monster monster) {
		monster.jump();
		monster.showMe();
		hero.showMe();
		hero.run();
		hero.attack();
		monster.attack();
		if (hero.getMagic() > monster.getPower()) {
			System.out.println(hero.getName() + "战胜了" + monster.getName());
		} else {
			System.out.println(hero.getName() + "在跟" + monster.getName()
					+ "的战斗中阵亡了！");
		}
	}

	public Monster creatMonster(int choice) {
		Monster monster = null;
		switch (choice) {
		case 1:
			monster = new LandMonster();
			break;
		case 2:
			monster = new SkyMonster();
			break;
		case 3:
			monster = new SeaMonster();
			break;
		default:
			break;
		}
		return monster;
	}

	public Hero creatHero(int choice, String name, int magic) {
		Hero hero = null;
		switch (choice) {
		case 1:
			hero = new Magician(name, magic);
			break;
		case 2:
			hero = new Barbarian(name, magic);
			break;
		case 3:
			hero = new Ranger(name, magic);
			break;
		default:
			break;
		}
		return hero;
	}

	public Hero creatHero(int choice) {
		Hero hero = null;
		switch (choice) {
		case 1:
			hero = new Magician();
			break;
		case 2:
			hero = new Barbarian();
			break;
		case 3:
			hero = new Ranger();
			break;
		default:
			break;
		}
		return hero;
	}
}
